package com.doit.day02;

import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

public class _08_插入数据 {
    public static void main(String[] args) throws IOException {
        Connection conn = HbaseUtil.getConn();

        //是对表进行操作的
        Table table = conn.getTable(TableName.valueOf("doit:table_name"));

        ArrayList<Put> puts = new ArrayList<>();

        Put put = new Put("abchongrui".getBytes(StandardCharsets.UTF_8));
        put.addColumn("f1".getBytes(StandardCharsets.UTF_8),"name".getBytes(StandardCharsets.UTF_8),"zss".getBytes(StandardCharsets.UTF_8));
        put.addColumn("f2".getBytes(StandardCharsets.UTF_8),"age".getBytes(StandardCharsets.UTF_8),"18".getBytes(StandardCharsets.UTF_8));
        put.addColumn("f3".getBytes(StandardCharsets.UTF_8),"gender".getBytes(StandardCharsets.UTF_8),"male".getBytes(StandardCharsets.UTF_8));
        put.addColumn("f1".getBytes(StandardCharsets.UTF_8),"address".getBytes(StandardCharsets.UTF_8),"beijing".getBytes(StandardCharsets.UTF_8));
        puts.add(put);
        Put put1 = new Put("abchr".getBytes(StandardCharsets.UTF_8));
        put1.addColumn("f1".getBytes(StandardCharsets.UTF_8),"friend".getBytes(StandardCharsets.UTF_8),"wuyifan".getBytes(StandardCharsets.UTF_8));
        put1.addColumn("f2".getBytes(StandardCharsets.UTF_8),"where".getBytes(StandardCharsets.UTF_8),"jinqule".getBytes(StandardCharsets.UTF_8));
        put1.addColumn("f3".getBytes(StandardCharsets.UTF_8),"job".getBytes(StandardCharsets.UTF_8),"freeeat".getBytes(StandardCharsets.UTF_8));
        put1.addColumn("f1".getBytes(StandardCharsets.UTF_8),"address".getBytes(StandardCharsets.UTF_8),"beijing".getBytes(StandardCharsets.UTF_8));
        puts.add(put1);
        Put put2 = new Put("abchong".getBytes(StandardCharsets.UTF_8));
        put2.addColumn("f1".getBytes(StandardCharsets.UTF_8),"brother".getBytes(StandardCharsets.UTF_8),"wujing".getBytes(StandardCharsets.UTF_8));
        put2.addColumn("f2".getBytes(StandardCharsets.UTF_8),"job".getBytes(StandardCharsets.UTF_8),"yanyuan".getBytes(StandardCharsets.UTF_8));
        put2.addColumn("f3".getBytes(StandardCharsets.UTF_8),"money".getBytes(StandardCharsets.UTF_8),"10000".getBytes(StandardCharsets.UTF_8));
        put2.addColumn("f1".getBytes(StandardCharsets.UTF_8),"address".getBytes(StandardCharsets.UTF_8),"shanghai".getBytes(StandardCharsets.UTF_8));
        puts.add(put2);
        Put put3 = new Put("abcrui".getBytes(StandardCharsets.UTF_8));
        put3.addColumn("f1".getBytes(StandardCharsets.UTF_8),"boss".getBytes(StandardCharsets.UTF_8),"xiaotao".getBytes(StandardCharsets.UTF_8));
        put3.addColumn("f2".getBytes(StandardCharsets.UTF_8),"age".getBytes(StandardCharsets.UTF_8),"18".getBytes(StandardCharsets.UTF_8));
        put3.addColumn("f3".getBytes(StandardCharsets.UTF_8),"gender".getBytes(StandardCharsets.UTF_8),"male".getBytes(StandardCharsets.UTF_8));
        put3.addColumn("f1".getBytes(StandardCharsets.UTF_8),"address".getBytes(StandardCharsets.UTF_8),"shanghai".getBytes(StandardCharsets.UTF_8));
        puts.add(put3);
        table.put(puts);

        table.close();
        conn.close();

    }
}
